@extends("admin.base")
@section("contents")
    <div class="row" style="font-family: 'UKIJ Ekran'">
        <div class="col-lg-11 m-auto">
            <div class="card">
                <div class="card-body">
                    <div class="table-responsive">
                        <a href="addmovie">
                            <button class="btn btn-outline-primary ">添加信息</button>
                        </a>
                        <button onclick="reload()" class="btn  bi bi-arrow-clockwise "
                                style="height: 40px;width: 40px;"></button>
                        <table class="table table-primary table-striped mb-0 " style="text-align: center">
                            <tr>
                                <th>id</th>
                                <th>movie_ch</th>
                                <th>movie_uy</th>
                                <th>image</th>
                                <th>type</th>
                                <th>lang</th>
                                <th>country</th>
                                <th>score</th>
                                <th>year</th>
                                <th>description</th>
                                <th>order</th>
                                <th>created_at</th>
                                <th>updated_at</th>
                                <th>操作</th>
                            </tr>
                            @foreach($movie as $movie)
                                <tr style="line-height: 40px">
                                    <td>{{$movie->id}}</td>
                                    <td>{{$movie->movie_ch}}</td>
                                    <td>{{$movie->movie_uy}}</td>
                                    <td><img src="{{$movie->image}} " style="width: 50px;height: 50px;"></td>
                                    <td>{{$movie->type}}</td>
                                    <td>{{$movie->lang}}</td>
                                    <td>{{$movie->country}}</td>
                                    <td>{{$movie->score}}</td>
                                    <td>{{$movie->year}}</td>
                                    <td>{{$movie->description}}</td>
                                    <td>{{$movie->order}}</td>
                                    <td>{{$movie->created_at}}</td>
                                    <td>{{$movie->updated_at}}</td>
                                    <td>
                                        <a href="updatemovie?id={{$movie->id}}">
                                            <button class="btn btn-outline-primary">修改</button>
                                        </a>
                                        <button onclick="deletetmovie()" class="btn btn-outline-danger">删除
                                        </button>
                                    </td>
                                </tr>
                            @endforeach
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <style>
        .swal-overlay {
            background-color: rgba(43, 165, 137, 0.5);
        }
    </style>
@endsection
<div class="swal-overlay">

    @section("scripts")
        <script>
            function deletetmovie(id) {
                swal({
                    title: "请确认操作",
                    text: "数据被删除以后无法恢复，确认吗",
                    icon: "warning",
                    buttons: ["取消", "确认"],
                }).then(willDelete => {
                    if (willDelete) {
                        $.ajax({
                            url: "deletetmovie",
                            data: {"id": id},
                            type: "GET",
                            dataType: "json",
                            headers: {'X-CSRF-TOKEN': '{{csrf_token()}}'},
                            async: true,
                            success: function (req) {
                                if (req.err == 0) {
                                    swal({
                                        title: "操作成功",
                                        text: req.title,
                                        icon: "success",
                                        button: "知道了",
                                    }) , setTimeout(function () {
                                        location.reload();
                                    }, 1000)
                                } else {
                                    swal({
                                        title: "操作失败",
                                        text: req.title,
                                        icon: "error",
                                        button: "知道了",
                                    })
                                }
                            }
                        })
                    }
                })
            }
        </script>
        <script>
            function reload() {
                location.reload()
            }
        </script>
    @endsection
</div>
